留言板"今日留言数"的问题?

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:43:35
asp+access构建的留言板.让它显示"今日留言数" ?

(看了很多留言板的代码,基本上与"今日留言数" 有关的都是下面那段,但不理解"今日留言数" 是怎么统计出来的)

如下:其中access中表admin含有today_time,today_count等

....

<%

on error resume next '找不到留言资料时忽略错误

Set Rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select * from admin"
Rs1.open sql,conn,3,2
if date <> today_time then
Rs1("today_count") = 0
end if
Rs1("today_time") = date
Rs1.update
Rs1.close
set Rs1 = nothing

....

%>

....

今日留言数:<font color="red" face="verdana"><%=today_count%></font>

....

一般用两种方法:
假设:
除了“表admin含有today_time,today_count等”,
还有一个保存留言的表为guestbook,含有write_time字段,用来保存留言时间

1)如果每天留言数不是很多
sql = "select count(*) from gustbook where datediff('d','"&date()&"',write_time)=0"
set rs = conn.execute(sql)
today_count = rs(0)
rs.close
set rs = nothing

1)如果每天留言数很多
当有人留言的时候,就执行这段代码

Set Rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select * from admin"
Rs1.open sql,conn,3,2
if datediff("d",date(),rs1("today_time"))<>0 then
Rs1("today_count") = 1
Rs1("today_time") = date() '这句写在if块里,提高效率
else
Rs1("today_count") = Rs1("today_count") + 1
end if
Rs1.update
Rs1.close
set Rs1 = nothing

'下面的代码读取当天留言数
sql = "select today_count from admin where datediff('d','"&date()&&quo